package com.dymall.controller;

import com.dymall.common.utils.BeanUtils;
import com.dymall.domain.dto.OrderFormDTO;
import com.dymall.domain.po.Order;
import com.dymall.domain.vo.OrderVO;
import com.dymall.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Api(tags = "订单管理接口")
@RestController
@RequestMapping("/orders")
@RequiredArgsConstructor
public class OrderController {
    private final OrderService orderService;

    @ApiOperation("创建订单")
    @PostMapping
    public Long CreateOrder(@RequestBody OrderFormDTO orderFormDTO){
        return orderService.createOrder(orderFormDTO);
    }

    @ApiOperation("根据id查询订单")
    @GetMapping("{id}")
    public OrderVO queryOrderById(@PathVariable("id") Long id){
        Order order = orderService.getById(id);
        return BeanUtils.copyBean(order, OrderVO.class);
    }

    @ApiOperation("标记订单已支付")
    @ApiImplicitParam(name = "orderId", value = "订单id", paramType = "path")
    @PutMapping("/{orderId}")
    public void markOrderPaySuccess(@PathVariable("orderId") Long oederId){
        orderService.markOrderPaySuccess(oederId);
    }

}
